from selenium import webdriver
from pk.common.dingwei import Common
from pk.public.login import crmlogin
import os
import time
import unittest
from selenium.webdriver.common.action_chains import ActionChains


class normal_login(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.get("http://182.92.197.48:8080/index.html#/login?redirect=%2F404")
        self.driver.maximize_window()
        time.sleep(5)
        print("starttime:" + time.strftime("%Y-%m%d-%H-%M-%S", time.localtime(time.time())))

    def tearDown(self):
        print("endTime:" + time.strftime("%Y-%m%d-%H-%M-%S", time.localtime(time.time())))
        filedir = "E:/test/screenshot/"
        if not os.path.exists(filedir):
            os.makedirs(filedir)
        screen_name = filedir + time.strftime("%Y-%m%d-%H-%M-%S", time.localtime(time.time())) + '.png'
        self.driver.get_screenshot_as_file(screen_name)
        self.driver.quit()

# 检查客户管理页面显示
    def testKehu01_01(self):
        crmlogin(self.driver).login_name('18812345678')
        crmlogin(self.driver).login_password("123456")
        time.sleep(5)
        Common(self.driver).findElement('Xpath','//div[text()="客户管理"]').click()
        time.sleep(10)
        shouyeshow_1 = Common(self.driver).findElement('Xpath','//span[text() = "仪表盘"]')
        shouyeshow_2 = Common(self.driver).findElement('Xpath','//span[text()="待办事项"]')
        shouyeshow_3 = Common(self.driver).findElement('Xpath', '//li/span[text()="线索"]')
        shouyeshow_4 = Common(self.driver).findElement('Xpath', '//li/span[text()="客户"]')
        self.assertEqual("仪表盘", shouyeshow_1.text)
        self.assertEqual("待办事项", shouyeshow_2.text)
        self.assertEqual("线索", shouyeshow_3.text)
        self.assertEqual("客户", shouyeshow_4.text)
        time.sleep(5)

    #点击线索，检查显示
    def testxiansuo01_01(self):
        crmlogin(self.driver).login_name('18812345678')
        crmlogin(self.driver).login_password("123456")
        time.sleep(8)
        Common(self.driver).findElement('Xpath','//div[text()="客户管理"]').click()
        time.sleep(15)
        Common(self.driver).findElement('Xpath', '//li/span[text()="线索"]').click()
        time.sleep(5)
        xiansuo=Common(self.driver).findElement('Xpath','//*[@id="crm-main-container"]/div/div/div[1]/div[1]')
        xiansuo_1=Common(self.driver).findElement('Xpath','//*[@id="crm-main-container"]/div/div/div[1]/div[3]/button')
        xiansuo_2=Common(self.driver).findElement('Xpath','//*[@id="crm-main-container"]/div/div/div[1]/div[3]/div/div/div')

        time.sleep(3)
        self.assertEqual("线索管理", xiansuo.text)
        self.assertEqual("新建线索", xiansuo_1.text)
        self.assertEqual("更多", xiansuo_2.text)
    #
    # #点击新建搜索，检查新建搜索页面显示
    def testxiansuo01_02(self):
        crmlogin(self.driver).login_name('18812345678')
        crmlogin(self.driver).login_password("123456")
        time.sleep(8)
        Common(self.driver).findElement('Xpath','//div[text()="客户管理"]').click()
        time.sleep(18)
        Common(self.driver).findElement('Xpath', '//li/span[text()="线索"]').click()
        time.sleep(8)
        Common(self.driver).findElement('Xpath','//*[@id="crm-main-container"]/div/div/div[1]/div[3]/button').click()
        check_2=Common(self.driver).findElement('Xpath','//span[text() = "新建线索"]')
        time.sleep(2)
        check_3 = Common(self.driver).findElement('Xpath', '/html/body/div[2]/div/div[1]/div/div[2]/div/div[2]/div/div/form/div[1]/label/div/div')
        check_5=Common(self.driver).findElement('Xpath','/html/body/div[2]/div/div[1]/div/div[2]/div/div[2]/div/div/form/div[2]/label/div/div')
        check_6=Common(self.driver).findElement('Xpath','//div/button/span[text()="保存"][1]')
        check_7=Common(self.driver).findElement('Xpath','//div/button/span[text()="取消"][1]')
        self.assertEqual('新建线索',check_2.text)
        self.assertEqual('线索', check_3.text)
        self.assertEqual('线索来源', check_5.text)
        self.assertEqual('保存', check_6.text)
        self.assertEqual('取消', check_7.text)
        time.sleep(3)

    #
    # #新建线索
    def testxiansuo01_03(self):
        crmlogin(self.driver).login_name('18812345678')
        crmlogin(self.driver).login_password("123456")
        time.sleep(8)
        Common(self.driver).findElement('Xpath','//div[text()="客户管理"]').click()
        time.sleep(18)
        Common(self.driver).findElement('Xpath', '//li/span[text()="线索"]').click()
        time.sleep(8)
        Common(self.driver).findElement('Xpath','//*[@id="crm-main-container"]/div/div/div[1]/div[3]/button').click()
        time.sleep(8)
        Common(self.driver).findElement('Xpath','//div[2]/div/div/form/div[1]/div/div[1]/input').send_keys("testtest0005")
        Common(self.driver).findElement('Xpath', '//div/button/span[text()="保存"][1]').click()
        time.sleep(2)
        check_a = Common(self.driver).findElement('Xpath', '//div[@role="alert"]/p')
        self.assertEqual('添加成功', check_a.text)

    #新建线索，检查线索列表显示
    def testxiansuo01_04(self):
        crmlogin(self.driver).login_name('18812345678')
        crmlogin(self.driver).login_password("123456")
        time.sleep(8)
        Common(self.driver).findElement('Xpath','//div[text()="客户管理"]').click()
        time.sleep(18)
        Common(self.driver).findElement('Xpath', '//li/span[text()="线索"]').click()
        time.sleep(8)
        Common(self.driver).findElement('Xpath','//*[@id="crm-main-container"]/div/div/div[1]/div[3]/button').click()
        time.sleep(8)
        ee=Common(self.driver).findElement('Xpath','//div[2]/div/div/form/div[1]/div/div[1]/input').send_keys("testtest00009")
        Common(self.driver).findElement('Xpath', '//div/button/span[text()="保存"][1]').click()
        time.sleep(4)
        dd= Common(self.driver).findElement('Xpath', '//*[@id="crm-table"]/div[4]/div[2]/table/tbody/tr[1]/td[2]/div')
        self.assertEqual("testtest00009", dd.text)

    #删除线索检查显示
    def testxiansuo01_05(self):
        crmlogin(self.driver).login_name('18812345678')
        crmlogin(self.driver).login_password("123456")
        time.sleep(8)
        Common(self.driver).findElement('Xpath', '//div[text()="客户管理"]').click()
        time.sleep(18)
        Common(self.driver).findElement('Xpath', '//li/span[text()="线索"]').click()
        time.sleep(8)
        Common(self.driver).findElement('Xpath', '//*[@id="crm-main-container"]/div/div/div[1]/div[3]/button').click()
        time.sleep(8)
        ee = Common(self.driver).findElement('Xpath', '//div[2]/div/div/form/div[1]/div/div[1]/input').send_keys("testtest0009")
        Common(self.driver).findElement('Xpath', '//div/button/span[text()="保存"][1]').click()
        time.sleep(4)
        Common(self.driver).findElement('Xpath', '//*[@id="crm-table"]/div[4]/div[2]/table/tbody/tr[1]/td[1]/div/label/span/span').click()
        time.sleep(3)
        Common(self.driver).findElement('Xpath', '//*[@id="crm-main-container"]/div/div/div[2]/div[1]/div[2]/div[2]/div[4]').click()
        time.sleep(3)
        Common(self.driver).findElement('Xpath', '/html/body/div[2]/div/div[3]/button[2]/span').click()
        time.sleep(3)
        check_aa = Common(self.driver).findElement('Xpath', '//div[@role="alert"]/p')
        self.assertEqual('删除成功', check_aa.text)

    #删除线索后检查线索列表显示
    def testxiansuo01_06(self):
        crmlogin(self.driver).login_name('18812345678')
        crmlogin(self.driver).login_password("123456")
        time.sleep(8)
        Common(self.driver).findElement('Xpath', '//div[text()="客户管理"]').click()
        time.sleep(18)
        Common(self.driver).findElement('Xpath', '//li/span[text()="线索"]').click()
        time.sleep(8)
        Common(self.driver).findElement('Xpath', '//*[@id="crm-main-container"]/div/div/div[1]/div[3]/button').click()
        time.sleep(8)
        ee = Common(self.driver).findElement('Xpath', '//div[2]/div/div/form/div[1]/div/div[1]/input').send_keys(
            "testtest00012")
        Common(self.driver).findElement('Xpath', '//div/button/span[text()="保存"][1]').click()
        time.sleep(4)
        Common(self.driver).findElement('Xpath',
                                        '//*[@id="crm-table"]/div[4]/div[2]/table/tbody/tr[1]/td[1]/div/label/span/span').click()
        time.sleep(3)
        Common(self.driver).findElement('Xpath',
                                        '//*[@id="crm-main-container"]/div/div/div[2]/div[1]/div[2]/div[2]/div[4]').click()
        time.sleep(3)
        Common(self.driver).findElement('Xpath', '/html/body/div[2]/div/div[3]/button[2]/span').click()
        time.sleep(3)
        check_cc = Common(self.driver).findElement('Xpath',"//*[@id='crm-table']/div[4]/div[2]/table/tbody/tr[1]/td[2]/div" )
        self.assertNotEqual('testtest00012', check_cc.text)
